package com.cqgc.controller;

import com.cqgc.domain.Book;
import com.cqgc.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author fengzongfu
 */
@RestController
@RequestMapping("book")
public class BookController {

    //注入业务对象
    @Autowired
    private BookService bookService;

    //新增, 通过请求体传递新增的数据
    //@RequestBody 获取请求体数据转换为java对象
    @PostMapping("save")
    public boolean save(@RequestBody Book book){
        bookService.save(book);
        return true;
    }

    //删除,通过路径变量传递id数据
    @PostMapping("delete")
    public boolean delete(Integer id){
        bookService.delete(id);
        return true;
    }

    //修改, 通过请求体传递新增的数据
    @PostMapping("update")
    public boolean update(@RequestBody Book book){
        bookService.update(book);
        return true;
    }

    //查询所有书
    @GetMapping("getAll")
    public List<Book> getAll(){
        return bookService.getAll();
    }

    //查询一本书，通过路径变量传递id数据
    @GetMapping("getById")
    public Book getById(Integer id){
        return  bookService.getById(id);
    }
}
